<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .image-item{
      display: block;
      height: 300px;
      margin-bottom: 50px;
    }
  </style>
</head>
<body>
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=1013965408,4219624876&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=3466021905,3150087336&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=510619069,781164079&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=749950672,3589653222&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=1553894825,1476958469&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=953273242,2194617125&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=1272756247,2807396345&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=1704407319,118122643&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=1013965408,4219624876&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=2335833069,1920942323&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=3600276043,1053571603&fm=193&f=GIF" alt="">
  <img class="image-item" src="" lazyLoad="true" data-original="https://t7.baidu.com/it/u=2420496430,2829916896&fm=193&f=GIF" alt="">
  <script>
      let viewHeight = document.documentElement.clientHeight
      console.log(viewHeight);

    function lazyLoad() {
       let eles = document.querySelectorAll('img[data-original][lazyLoad]')
        // console.log(eles);
       eles.forEach(item => {
           let rect
           rect = item.getBoundingClientRect()
           console.log(rect);
           if (rect.bottom >= 0 && rect.top < viewHeight) {
            // let img = new Image()
            item.src =item.dataset.original 
            item.removeAttribute('data-original')
            item.removeAttribute('lazyLoad')
           }
       })
    }
    lazyLoad()
    document.addEventListener('scroll',lazyLoad)
  </script>
</body>
</html>